<?php
require "library/okch.inc";



class StylesModule extends Module
{
	public $helper;
	
	public function __config()
	{
		
		$this->helper = new OKHelper($this->site);
		$this->page->add_js("styles.js");
	}
	
	public function __default()
	{
		header("Location: /admin/styles/manage");
		return;
	}
	
	public function AddAction()
	{
		session_start();
		
		if ( !isset( $_SESSION['uid'] ) )
		{
			session_destroy();
			header("Location: /admin/");
			return;
		}
		
		// Show page
		$this->helper->control_base();
		$this->helper->get_data();
		$this->helper->menu_set_state("styles add");
		
		$this->page->title("_ControlPanel", true);
		$this->page->setVar("admin_name", $this->helper->data['name']);
		
		$this->page->loadTplToVar("menuForm", "control/menu.tpl");
	}
	
	public function ManageAction()
	{
		session_start();
		
		if ( !isset( $_SESSION['uid'] ) )
		{
			session_destroy();
			header("Location: /admin/");
			return;
		}
		
		// Show page
		$this->helper->control_base();
		$this->helper->get_data();
		$this->helper->menu_set_state("styles/manage");
		
		$this->page->title("_ControlPanel", true);
		$this->page->setVar("admin_name", $this->helper->data['name']);
		
		$this->page->loadTplToVar("menuForm", "control/menu.tpl");
		$this->page->loadTplToVar("content", "styles/page.tpl");
		
			// Styles
		{
			$this->db->select("*", "styles")->q("ORDER BY `id` ASC")->result();
			$arr = array();
			$this->db->while_fetch_array(&$arr, function($var,&$a){
				$a[] = $var;
			});
			
			$this->page->processTemplateFunction("list", $arr, "styles/list_view.tpl", function($key,$val,$tpl){
				$tpl->setVar("pr_id", $val['id']);
				$tpl->setVar("pr_title", $val['title']);
				$tpl->setVar("pr_image", "/styles/".$val['preview']);
			});
		}
	}
	
	public function ViewAction()
	{
		session_start();
		
		if ( !isset( $_SESSION['uid'] ) )
		{
			session_destroy();
			header("Location: /admin/");
			return;
		}
		
		// Show page
		$this->helper->control_base();
		$this->helper->get_data();
		$this->helper->menu_set_state("styles_manage");
		
		$this->page->title("_ControlPanel", true);
		$this->page->setVar("admin_name", $this->helper->data['name']);
		
		$this->page->loadTplToVar("menuForm", "control/menu.tpl");
		
	
	}
}